package com.bcmusic.music.dao;

import com.bcmusic.music.pojo.MusicPermission;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/****
 * @Author:admin
 * @Description:MusicPermission的Dao
 * @Date 2019/6/14 0:12
 *****/
public interface MusicPermissionMapper extends Mapper<MusicPermission> {
    /**
     * 分页查询许可的id
     *
     * @param page
     * @param size
     * @return
     */
    @Select("SELECT music_id FROM music_permission WHERE valid_status=1 GROUP BY music_id ORDER BY music_id desc LIMIT ${page},${size}")
    public List<Integer> findMusicIdList(@Param("page") Integer page, @Param("size") Integer size);

    /**
     * 查询对应十个id的音乐
     *
     * @param musicIdList
     * @return
     */
    @Select("<script>"
            + "SELECT * FROM music_permission where music_id IN "
            + "<foreach item='item' index='index' collection='musicIdList' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            +"and valid_status=1"
            + "</script>")
//    @Select("SELECT * from music_permission WHERE music_id in#{musicIdList} and valid_status=1")
    List<MusicPermission> findMusicPermissionByMusicIdList(@Param("musicIdList") List<Integer> musicIdList);

    /**
     * 根据类型以及音乐id查询音乐详细的授权信息
     * @param musicId
     * @param type
     * @return
     */
    @Select("SELECT * FROM music_permission WHERE music_id = #{music_id} AND type =#{type} AND valid_status=1")
    MusicPermission getMusicPermissionDetail(@Param("music_id") Integer musicId, @Param("type") Integer type);

    /**
     * 根据音乐id查询其授权转让信息
     * @param musicId
     * @return
     */
    @Select("SELECT* from music_permission WHERE music_id=#{music_id} and valid_status in(0,1)")
    MusicPermission getMusicTranfer(@Param("music_id")Integer musicId);
}
